Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR fixes config.root handling to support running sub-project tests with specified config in monorepo setups. Previously, the CLI's root option would override the config file's root setting. Now, the config file's root is properly respected.
Key changes:
- Separated the concept of
cwd(where to look for config) fromroot(project root from config) - Added fallback logic to set config.root to cwd if not specified in config
- Updated example configs to explicitly set
root: __dirname
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/core/src/cli/init.ts | Refactored resolveConfig to accept cwd instead of root, added fallback logic for config.root |
| examples/node/rstest.config.ts | Added explicit root: __dirname to example config |
| e2e/projects/fixtures/packages/client/rstest.config.ts | Added root: __dirname to each project configuration |
| e2e/projects/index.test.ts | Added test to verify config root is respected when specified via -c flag |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const mergedConfig = mergeWithCLIOptions(config, options); | ||
|
|
||
| if (!mergedConfig.root) { | ||
| mergedConfig.root = options.cwd; | ||
| } |
There was a problem hiding this comment.
The mergeWithCLIOptions function includes 'root' in its keys array (line 52), which causes it to override config.root with options.root when the --root CLI flag is provided. This defeats the purpose of this PR, which is to respect the config file's root setting.
The issue: when options.root is provided via CLI (e.g., --root packages/client), it's still a relative string that gets copied into config.root, potentially overriding an absolute path like __dirname from the config. Later, in RstestCore, this relative path would be resolved using the wrong base, resulting in incorrect paths like /monorepo/packages/client/packages/client.
The solution: Remove 'root' from the keys array in mergeWithCLIOptions (line 52). This way:
- If the config has a
root, it's preserved - If the config doesn't have a
root, the fallback at lines 120-122 sets it tooptions.cwd - The CLI
--rootonly affects where to look for the config file (viaoptions.cwd), not the finalconfig.root
This aligns with the PR's intent to respect the config file's root setting while allowing --root to control where configs are loaded from.
Summary
fix: should respect config.root option. support run sub-project tests with specified config &
rootconfiguration in monorepo's root.https://rstest.rs/config/test/root
Related Links
Checklist